const path = require('path');
const glob=require('glob')
const CopyPlugin = require("copy-webpack-plugin");
const CleanCSS = require('clean-css')
const moment = require('moment');

let version=timeSet();

module.exports = {
  //entry: './src/index.js',
  entry:glob.sync('./static/js/*.js'),
  target:['web', 'es5'],
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist/插件'+version)
  },
  module:{
    rules: [
      {
        test: /\.js/, //babel转化es6到es5
        // exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: [
              ['@babel/preset-env', { targets: "defaults" }]
            ]
            // plugins: ["@babel/plugin-transform-runtime"]
          }
        }
      },
      // {
      //   test: /\.js/,
      //   use: {
      //     loader: 'worker-loader',
      //   }
      // }
    ]
  },
  plugins: [
    new CopyPlugin({
      patterns: [
        { from: "static/css",
          to: "css",
          // transform: function (content) {
          // return new CleanCSS({}).minify(content).styles //压缩css文件
          // }
        },
        { from: "static/lib", to: "lib" },
        { from: "manifest.json", to: "" },
        { from: "16.png", to: "" },
        { from: "48.png", to: "" },
        { from: "128.png", to: "" }
      ],
    }),
  ],

};

function timeSet(){
  // 创建一个新的Date对象，它将包含当前的日期和时间
const now = new Date();

// 获取年月日时分秒
const year = now.getFullYear();        // 年份
const month = now.getMonth() + 1;      // 月份，getMonth()返回的月份是从0开始的，所以需要+1
const day = now.getDate();            // 日
const hour = now.getHours();          // 小时
const minute = now.getMinutes();      // 分钟
const second = now.getSeconds();      // 秒钟

// 如果需要，可以添加前导零
const formattedMonth = month.toString().padStart(2, '0');
const formattedDay = day.toString().padStart(2, '0');
const formattedHour = hour.toString().padStart(2, '0');
const formattedMinute = minute.toString().padStart(2, '0');
const formattedSecond = second.toString().padStart(2, '0');

// 拼接字符串
const dateTimeString = `${year}${formattedMonth}${formattedDay}${formattedHour}`;
return dateTimeString;
//console.log(dateTimeString); // 输出格式类似于 "2024-09-28 15:23:45"
}